package Stack;

public class SeqStack<E> implements Stack<E>{

    private E[] elements;
    private int top;
    public SeqStack() {
        this(64);
    }

    public SeqStack(int length) {
        this.elements= (E[]) new Object[length];
        this.top=0;
    }

    public int size(){
        return top-1;
    }

    @Override
    public boolean isEmpty() {
        return this.top==0;
    }

    @Override
    public void push(E x) {
        elements[top]=x;
        top++;
    }

    @Override
    public E peek() {
        return elements[top-1];
    }

    @Override
    public E pop() {
        E temp = elements[top-1];
        top--;
        return temp;
    }
}
